<template>
  <div class="page">
    <div class="songListInformation">
      <img :src="picUrl" />
      <div class="backgroundImg">
        <div class="listImg">
          <img :src="picUrl + '?imageView=1&type=webp&thumbnail=369x0'" />
        </div>
        <p>{{ intro }}</p>
      </div>
    </div>
    <div class="listTop">歌曲列表</div>
    <ul class="newsong" v-if="songList.length > 0">
      <li v-for="(s, index) in songList" :key="s.id">
        <SongItem :item="s" @play="$emit('play', $event)">{{
          index + 1
        }}</SongItem>
      </li>
    </ul>
    <Loading v-if="isLoading"></Loading>
    <div class="loadingmore" @click="loadMore">
      {{ str ? "点击加载更多..." : "已经没有了~" }}
    </div>
    <div class="footer"></div>
  </div>
</template>
<script>
import Loading from "@/components/Loading";
import SongItem from "@/components/SongItem";
export default {
  data() {
    return {
      str: true,
      listID: null,
      picUrl: null,
      intro: null,
      songList: [],
      page: 1,
      isLoading: true,
    };
  },
  components: {
    Loading,
    SongItem,
  },
  created() {
    this.loadMusic();
  },
  methods: {
    loadMusic() {
      this.listID = this.$route.params.id;
      this.axios
        .get("/playlist/detail?id=" + this.listID)
        .then((data) => {
          this.picUrl = data.data.playlist.coverImgUrl;
          this.intro = data.data.playlist.name;
          let trackIDS = data.data.playlist.trackIds.slice(
            (this.page - 1) * 20,
            20 * this.page
          );
          if (trackIDS == "") {
            this.str = false;
          }
          let ids = trackIDS.map((d) => {
            return d.id;
          });
          return ids.join(",");
        })
        .then((ids) => {
          this.axios
            .get("http://music.kele8.cn/song/detail?ids=" + ids)
            .then((songData) => {
              this.isLoading = false;
              if (!songData.data.songs) {
                return
              } else {
                songData.data.songs.map((d) => {
                  d.song = {
                    artists: d.ar,
                  };
                  this.songList.push(d);
                  return d;
                });
              }
            });
        });
    },
    loadMore() {
      this.page++;
      this.isLoading = true;
      this.loadMusic();
    },
  },
};
</script>
<style lang="less" scoped>
.page {
  overflow-y: scroll;
  position: fixed;
  top: 0;
  width: 100vw;
  height: 100vh;
  background-color: #eee;
  .songListInformation {
    position: relative;
    width: 100vw;
    height: 186px;
    overflow: hidden;
    .backgroundImg {
      position: absolute;
      top: 0;
      left: 0;
      width: 100vw;
      height: 186px;
      background: rgba(255, 192, 206, 0.74);
      overflow: hidden;
      img {
        width: 100%;
        height: auto;
      }
    }
    .listImg {
      position: absolute;
      z-index: 10;
      width: 126px;
      height: 126px;
      top: 30px;
      left: 15px;
      img {
        height: 100%;
        width: 100%;
      }
    }
    p {
      display: inline-block;
      position: absolute;
      top: 30px;
      left: 156px;
      font-size: 17px;
      color: #fefefe;
    }
  }
  .listTop {
    color: #666;
    background-color: #eeeff0;
    padding: 0px 10px;
    font-size: 12px;
    line-height: 23px;
  }
  .newsong {
    background-color: #fff;
  }
}
.loadingmore {
  background-color: #fff;
  text-align: center;
}
/deep/.index {
  color: #999;
  font-size: 17px;
  width: 40px;
  height: 55px;
  text-align: center;
  line-height: 55px;
}
/deep/.songItem {
  padding: 0px 0px;
}
/deep/.playbtn {
  margin-right: 8px;
}
.footer {
  height: 64px;
  width: 100vw;
}
</style>